<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('医护人员列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
<!--                        <li>-->
<!--                            <label>用户编号：</label>-->
<!--                            <input type="text" name="userId"/>-->
<!--                        </li>-->
                        <li>
                            <label>医生性别：</label>
                            <select name="doctorSex" th:with="type=${@dict.getType('sys_user_sex')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>职称：</label>
                            <input type="text" name="doctorTitle"/>
                        </li>
                        <li>
                            <label>科室：</label>
                            <input type="text" name="subject"/>
                        </li>
                        <li>
                            <label>教育程度：</label>
                            <input type="text" name="education"/>
                        </li>
                        <li>
                            <label>医生姓名：</label>
                            <input type="text" name="doctorName"/>
                        </li>
                        <li>
                            <label>手机号码：</label>
                            <input type="text" name="phone"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:doctor:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:doctor:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:doctor:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:doctor:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:doctor:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:doctor:remove')}]];
    var doctorSexDatas = [[${@dict.getType('sys_user_sex')}]];
    var prefix = ctx + "system/doctor";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "医护人员",
            columns: [{
                checkbox: true
            },
                {
                    field: 'doctorId',
                    title: '医生编号',
                    visible: false
                },
                // {
                //     field: 'userId',
                //     title: '用户编号'
                // },
                {
                    field: 'doctorSex',
                    title: '医生性别',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(doctorSexDatas, value);
                    }
                },
                {
                    field: 'doctorTitle',
                    title: '职称'
                },
                {
                    field: 'subject',
                    title: '科室'
                },
                {
                    field: 'education',
                    title: '教育程度'
                },
                {
                    field: 'doctorName',
                    title: '医生姓名'
                },
                {
                    field: 'phone',
                    title: '手机号码'
                },
                {
                   field: 'createTime',
                   title:'创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'left',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.doctorId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.doctorId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        if(row.userId===undefined||row.userId===null||row.userId.length===0){
                            actions.push('<a style=" margin-left: 5px" class="btn btn-info btn-xs ' +  removeFlag+'" href="javascript:void(0)" onclick="fun(\'' + row.doctorId + '\')"><i class="fa fa-user-plus"></i>开通登录帐号</a>');
                        }

                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

   let fun= function(uuid){
      // $.operate.post("/registerDoctor/"+uuid);
       $.modal.confirm("是否确定为该医护人员开通登录帐号，密码默认为123456",function(){
           $.ajax({
               url:"/registerDoctor/"+uuid,
               method:"post",
               success:function(res){
                   //console.log(res);
                   if(res.code===0){
                       $.modal.msgSuccess("开通成功");
                       $.table.refresh();
                   }else if(res.code===500){
                       $.modal.msgError(res.msg);
                   }

               },
               error:function(err){
                   //console.error(err);
                   $.modal.msgError(err);

               }

           })
       });

   }
</script>
</body>
</html>